package com.itheima;
import java.util.ArrayList;
public class ArrayListDemo7 {
    public static void main(String[] args) {
        //1.创建集合
        ArrayList<User> list = new ArrayList<User>();
        //2.创建三个用户对象
        User u1=new User("001","zhngsan","123");
        User u2=new User("002","li","456");
        User u3=new User("003","zhngsan","789");
   //3.添加元素
        list.add(u1);
        list.add(u2);
        list.add(u3);
        //4.调用方法看id是否存在
        boolean flag = contains(list, "009");
        System.out.println(flag);
    }
    public static boolean contains(ArrayList<User> list,String id){
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getId().equals(id)){
                return true;
            }
        }
        return false;
    }
}
